from pyspark import SparkConf, SparkContext, StorageLevel

if __name__ == '__main__':
    # 构建SparkConf对象
    conf = SparkConf().setAppName("test").setMaster("local[*]")
    # 构建SparkContext执行环境入口对象
    sc = SparkContext(conf=conf)

    # 获取累加器对象
    acmlt = sc.accumulator(0)

    rdd = sc.parallelize(range(1, 11), 2)

    # print(rdd.glom().collect())

    def map_func(data):
        global acmlt
        acmlt += 1
        print(acmlt)

    rdd.map(map_func).collect()
    print(acmlt)
    # 最后acmlt结果 输出为10

